<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择项目信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>


<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目属性：</label>
                        <div class="layui-input-block">
                            <select id="business" name="business" lay-filter="business">
                                <option value="">请选择</option>
                                <option value="1">自营</option>
                                <option value="2">联营</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">资质类型</label>
                        <div class="layui-input-block">
                            <div id="engintype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目状态：</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }

    // 用证专用
    var use_type = getQueryVariable('use_type');
    if(use_type === undefined || use_type === false){
        use_type = '';
    }
    var apply_type = getQueryVariable('apply_type');
    if(apply_type === undefined || apply_type === false){
        apply_type = '';
    }


    var parent_dom = getQueryVariable('dom');
    var parent_page = getQueryVariable('page');

    layui.use(['laytp','table','form','soulTable'], function () {
        var table = layui.table, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_engin_page_achieve),where: {use_type: use_type, apply_type: apply_type}, page: true
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){
                xmselect_dan('engintype', res.data.engintype, res.data.is_engintype, function (res) {
                    searchTableFunc(form, table);
                });
                xmselect_dan('zhaotype', res.data.zhaotype, res.data.is_zhaotype, function (res) {
                    searchTableFunc(form, table);
                });

                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(res.data.is_state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else {
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }

                }
                $("#state").html(state_str);


                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:'checkbox',fixed:'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'name', title: '项目名称'}
                ,{field: 'engintype', title: '资质类型'}
                ,{field: 'expectfee', title: '项目金额(万元)'}
                ,{field: 'areas', title: '所在地'}
                ,{field: 'man_xiang_name', title: '业务对接人'}
                ,{field: 'actualdt', title: '实际开工日期'}
                ,{field: 'filishdt', title: '竣工验收日期'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }


            var index = $(".short_table_tbody tr" , parent.document).length;
            for(var i=0;i<data.length;i++){
                var str = '';
                str += '<tr>';
                str += '<td class="width35">'+(index + i + 1)+'</td>';
                str += '<td><input type="text" class="layui-input year bdate_y"></td>';
                str += '<td><input type="text" class="layui-input name" value="'+data[i].name+'"></td>';
                str += '<td style="width: 141px;">';
                str += '<div class="type type'+(index + i + 1)+'" key="'+(index + i + 1)+'"></div>';
                str += '</td>';
                str += '<td><input type="text" class="layui-input money" value="'+data[i].expectfee+'"></td>';
                str += '<td style="width: 171px;"><input type="text" class="layui-input addr" value="'+data[i].areas+'"></td>';
                str += '<td><input type="text" class="layui-input start_dt bdate_ymd" value="'+data[i].actualdt+'"></td>';
                str += '<td><input type="text" class="layui-input end_dt bdate_ymd" value="'+data[i].filishdt+'"></td>';
                str += '<td><input type="text" class="layui-input explain"></td>';

                if(data[i].jingcertinfo){
                    str += '<td><input type="text" readonly name="jingcert" key="'+data[i].jingcertinfo.id+'" value="'+data[i].jingcertinfo.person_name+'('+data[i].jingcertinfo.name+')'+'" class="layui-input jingcert" onclick="choose_cert(this,\'jingcert\')"></td>';
                }else{
                    str += '<td><input type="text" readonly name="jingcert" class="layui-input jingcert" onclick="choose_cert(this,\'jingcert\')"></td>';
                }

                if(data[i].shucertinfo){
                    str += '<td><input type="text" readonly name="shucert" key="'+data[i].shucertinfo.id+'" value="'+data[i].shucertinfo.person_name+'('+data[i].shucertinfo.name+')'+'" class="layui-input shucert" onclick="choose_cert(this,\'shucert\')"></td>';
                }else{
                    str += '<td><input type="text" readonly name="shucert" class="layui-input shucert" onclick="choose_cert(this,\'shucert\')"></td>';
                }

                str += '<td>'+public_show_file_deta('list_list', [],1)+'</td>';
                str += '</tr>';


                $("#list_list", parent.document).append(str);
                parent.xmselect_list_dan('type'+(index + i + 1), parent.pub_type, data[i].engintype_old);
                parent.set_list_render_xmselect([{name:'addr', data:parent.pub_addr, value:''}]);
            }



            parent.render_from();
            parent.render_date();
            parent.formValid(parent_dom);

            layer_close();
        });

    });
</script>
</body>
</html>
